package factoryMethod;

public class Plant {
	public static void main(String[] args) {
		//简单工厂模式
		Operation operation = plant("/");
		operation.setNum1(10);
		operation.setNum2(20);
		System.out.println(operation.getResult());
		
		//工厂方法模式
		Method method=new AddMethod();//在添加新功能的时候客户端只该这一句
		operation=method.getMethod();
		operation.setNum1(10);
		operation.setNum2(20);
		System.out.println(operation.getResult());
		
	}
	/**
	 * 简单工厂模式
	 * @author wangyilong
	 *
	 */
	public static Operation plant(String str){
		Operation operation;
		switch (str) {
		case "+":
			operation=new Add();
			break;
		case "-":
			operation=new Minus();
			break;
		case "*":
			operation=new Multiply();
			break;
		case "/":
			operation=new Divide();
			break;
		default:
			operation=new Operation();
			break;
		}
		return operation;
	}
}
